(function(){
    function GetJcMonitor(){
        this.init();
  
     
       
    }

    GetJcMonitor.prototype = {
        constructor:GetJcMonitor,
        init:function(){
            this.nodata = '<tr><td  colspan="12">暂无信息</td></tr>';
            var _this = this;
        
              $.datetimepicker.setLocale('ch');
				$('#endtime').datetimepicker({
                    format: 'Y-m-d',
                    value:new Date().dateadd("d", 1),
					maxDate: new Date().dateadd("d", 5),
					onChangeDateTime:function(dp,$input){
						var limitStart = new Date($('#begintime').val().replace('-','/'));
						var nowStart = new Date($('#endtime').val().replace('-','/'));
						if(limitStart > nowStart){
							$('#endtime').val(limitStart.format("YY-M-D"))

						}
					},
					timepicker: false
                });
                
                $('#begintime').datetimepicker({
                    format: 'Y-m-d',
                    value:new Date().dateadd("d", -1),
                    maxDate: new Date(),
					onChangeDateTime:function(dp,$input){
                        var limitStart = new Date($('#endtime').val().replace('-','/'));
						var nowStart = new Date($('#begintime').val().replace('-','/'));
						if(limitStart < nowStart){
							$('#begintime').val(limitStart.format("YY-M-D"))

						}
						
					},
					timepicker: false
                });
                

                this.getMonitorList(1);
            
                $("#searchBtn").unbind("click").click(function(){
                     _this.getMonitorList(1);
                });
                $.extend({page:function(pn){
                    _this.getMonitorList(pn);
                }});






        },
        getMonitorList:function( pn ){
            var _this = this;
            var ischecked = $("#ischecked").prop("checked");
            var state = ischecked ? "&state=1" : "";
            var stime = $("#begintime").val() + " 00:00:00";
            var etime = $("#endtime").val() + " 23:59:59";

            $.ajax({
                type:"get",
                url:"/sys?fid=201&type=1&stime="+stime+"&etime="+etime+state+"&ps=10&pn="+pn,
                dataType:"json",
                success:function( info ){
                    var code = info.code;
                    var desc = info.desc;
                    if( code == 1 )
                    {
                        var data = info.data;
                        var count = info.count;
                      
                        var stateArr = ["无赛果","有赛果","已计奖", "取消","已计奖(取消)"];
                        if( data.length )
                        {
                            var strArr = [];
                            data.forEach(function( value, key  ){
                                var itemid = value.itemid;
                                var leaguename = value.leaguename;
                                var matchname = value.matchname;
                                var htname = value.htname;
                                var rq = value.rq;
                                var gtname = value.gtname;
                                var stateIndex = value.status;
                                var state = stateArr[stateIndex];
                                var endtime = value.endtime;
                                var matchtime = value.matchtime;
                                var hs = "";
                                var gs = "";
                                var hhs ="";
                                var ghs = "";
                                if( stateIndex )
                                {
                                     hs = value.hs;
                                     gs = value.gs;
                                     hhs = value.hhs;
                                     ghs = value.ghs;
                                }

                                var trClass =  key%2 == 0 ? "even" : "odd";
                                var html = '<tr class="'+trClass+'"  >\
                                                <td>'+itemid+'</td>\
                                                <td>'+leaguename+'</td>\
                                                <td>'+matchname+'</td>\
                                                <td>'+htname+'</td>\
                                                <td>'+rq+'</td>\
                                                <td>'+gtname+'</td>\
                                                <td>'+endtime+'</td>\
                                                <td>'+matchtime+'</td>\
                                                <td>'+hs+'</td>\
                                                <td>'+gs+'</td>\
                                                <td>'+hhs+'</td>\
                                                <td>'+ghs+'</td>\
                                                <td>'+state+'</td>\
                                            </tr>';

                                    strArr.push( html );

                            });

                            $("#unticketList").html( strArr.join(""));
                          
                            
                            // 分页
                            var pn = count.pn;
                            var tp = count.tp;
                            var tr = count.tr;
                            $("#countpages").html( tp );
                            $("#countnums").html( tr );
        
                            var pageHtml = getPages(pn,tp, "$.page");

                            $("#paginationSel").html(pageHtml);



                        }
                        else
                        {
                            $("#unticketList").html(_this.nodata);

                        }

                    }
                    else
                    {
                        if( code == 2 )
                        {
                            location.href = "login.html";

                        }
                        else
                        {
                            $("#tipsContent").html( desc );
                            $("#loginoutModal").modal();

                        }
                    }


                }
            });


        },
   
      
      
    };





  new GetJcMonitor();

}());